{include header}
<div class="wrapper">
    {include header_menu}

    {include left_menu}
    <div class="main-container">
    <style>

    .table-striped>tbody>tr{
            cursor: pointer;
    }
    </style>
        <div class="padding-md">
            <table class="table table-striped table-bordered m-top-md" id="dataTable">
				<thead>
					<tr class="bg-dark-blue">
						<th>文章ID</th>
						<th>分类&FID</th>
						<th>作者&UID</th>
                        <th>标题</th>
                        <th>发表时间</th>
                        <th>浏览次数</th>
                        <th>评论数量</th>
                        <th>顶</th>
                        <th>踩</th>
                        <th>置顶</th>
                        <th>操作</th>

					</tr>
				</thead>
				<tbody>
                    {foreach $data as $v}
                    <tr onclick="edit_thread(['{$v.id}','{$v.title}','{$v.fid}'])">
                        <td>{$v.id}</td>
                        <td><?php echo $forum[$v['fid']]['name']; ?><small class="badge badge-success badge-square bounceIn animation-delay2 m-left-xs pull-right">{$v.fid}</small></td>
                        <td>{$v.user}<small class="badge badge-success badge-square bounceIn animation-delay2 m-left-xs pull-right">{$v.uid}</small></td>
                        <td>{$v.title}</td>
                        <td><?php echo date("Y-m-d H:i:s",$v['atime']); ?></td>
                        <td>{$v.views}</td>
                        <td>{$v.posts}</td>
                        <td>{$v.goods}</td>
                        <td>{$v.nos}</td>
                        <td>{if $v['top']==1}<span class="label label-success">板块置顶</span>{elseif $v['top']==2}<span class="label label-info">全站置顶</span>{else}无{/if}</td>
                        <td>
                            <button type="button" class="btn btn-success btn-xs" >修改</button>
                            <button type="button" class="btn btn-danger btn-xs">删除</button>
                        </td>
                    </tr>
                    {/foreach}


				</tbody>
			</table>
            <div class="smart-widget-body">


				<a href="{if $pageid==1}javascript:void(0);{else}{#WWW}admin{#EXP}thread?pageid={$pageid-1}{$fj}{/if}" class="btn btn-success marginTB-xs" {if $pageid==1}disabled{/if}><i class="fa fa-angle-double-left m-left-xs"></i> 上一页</a>

				<a href="{if $pageid==$page_count}javascript:void(0);{else}{#WWW}admin{#EXP}thread?pageid={$pageid+1}{$fj}{/if}" style="float:right" class="btn btn-success marginTB-xs" {if $pageid==$page_count}disabled{/if}>下一页<i class="fa fa-angle-double-right m-left-xs"></i></a>


			</div>
            <div class="row">
            <div class="col-md-12">
                <div class="smart-widget m-top-lg widget-dark-blue smart-widget-collapsed">
    				<div class="smart-widget-header">
    					发表文章
    					<span class="smart-widget-option">
    						<span class="refresh-icon-animated">
    							<i class="fa fa-circle-o-notch fa-spin"></i>
    						</span>

                            <a href="#" class="widget-collapse-option" data-toggle="collapse">
                                <i class="fa fa-chevron-up"></i>
                            </a>


                        </span>
    				</div>


    				<div class="smart-widget-inner" style="display: none;">
    					<div class="smart-widget-body">
                            <h2>说明</h2>
                            <section>
    		                    <p>与站前发表文章方式一样</p>
    		                </section>

                                <input type="hidden" name="gn" value="2">
                                <div class="form-group">
                                    <select id="forum" type="text" class="form-control" style="width:150px;margin-bottom:10px">
                                    <option value="-1">请选择一个分类</option>

                                    {foreach $forum as $v}
                                    <option value="{$v['id']}">{$v['name']}</option>
                                    {/foreach}

                                    </select>
                                </div>

    							<div class="form-group">
    								<label for="">标题</label>
    								<input type="text" id="title" name="user" class="form-control" >
    							</div>

                                <div class="form-group">
    								<label for="">文章内容</label>
    								<textarea id="editor" autofocus></textarea>
    							</div>


    							<button type="button" onclick="post_thread()" class="btn btn-success btn-sm">提交</button>

    					</div>
    				</div><!-- ./smart-widget-inner -->
    			</div>
            </div>

            <div class="col-md-12">
                <div class="smart-widget m-top-lg widget-dark-blue">
    				<div class="smart-widget-header">
    					修改文章
    					<span class="smart-widget-option">
    						<span class="refresh-icon-animated">
    							<i class="fa fa-circle-o-notch fa-spin"></i>
    						</span>

                            <a href="#" class="widget-collapse-option" data-toggle="collapse">
                                <i class="fa fa-chevron-up"></i>
                            </a>


                        </span>
    				</div>


    				<div class="smart-widget-inner">
    					<div class="smart-widget-body">
                            <h2>说明</h2>
                            <section>
    		                    <p>请在上面列表点击一个文章</p>
    		                </section>
                            <!-- <div class="row" style="margin-bottom:10px">
                                <div class="col-lg-2">
                                    <input type="text"  class="form-control">
                                </div>

                            </div> -->

                                <input type="hidden" id="id" name="id" value="2">
                                <div class="form-group">
                                    <select id="forum1" type="text" class="form-control" style="width:150px;margin-bottom:10px">
                                    <option value="-1">请选择一个分类</option>

                                    {foreach $forum as $v}
                                    <option value="{$v['id']}">{$v['name']}</option>
                                    {/foreach}

                                    </select>
                                </div>

    							<div class="form-group">
    								<label for="">标题</label>
    								<input type="text" id="title1" name="user" class="form-control" >
    							</div>

                                <div class="form-group">
    								<label for="">文章内容</label>
    								<textarea id="editor1" autofocus></textarea>
    							</div>


    							<button type="button" onclick="xiu_thread()" class="btn btn-success btn-sm">提交</button>

    					</div>
    				</div><!-- ./smart-widget-inner -->
    			</div>
            </div>


            </div>
        </div><!-- ENd box  -->

    </div>
</div>
{include footer}
<link href="{#WWW}Plugin/Simditor/css/simditor.css" type="text/css" rel="stylesheet">
<script src="{#WWW}Plugin/Simditor/js/edit.min.js"></script>
<script>
function xiu_thread(){
    $.ajax({
         url: window.location.pathname,
         type:"POST",
         cache: false,
         data:{id:$("#id").val(),gn:2,title:$("#title1").val(),content:editor1.textarea.val(),forum:$("#forum1").val()},
         dataType: 'json'
     }).then(function(e) {

         alert(e.info);
       }, function() {
         alert('请尝试重新提交');
       });
}
function edit_thread(json){

    $("#forum1").val(json[2]);
    $("#title1").val(json[1]);
    $("#id").val(json[0]);

    $.post(window.location.pathname,{id:$("#id").val(),gn:1},function(e){
            editor1.setValue(e);
    },"html");



}
function post_thread(){
    var forum = $("#forum").val();


    $.ajax({
         url: '/post',
         type:"POST",
         cache: false,
         data:{title:$("#title").val(),content:editor.textarea.val(),forum:forum},
         dataType: 'json'
     }).then(function(e) {

         alert(e.info);
       }, function() {
         alert('请尝试重新提交');
       });

}
$(function(){
    editor1 = new Simditor({
      textarea: $('#editor1'),
      upload: {
    	url: '{#WWW}post{#EXP}upload',
    	defaultImage: '{#WWW}Public/A/image/image.png',
    	params: null,
    	fileKey: 'photo',
    	connectionCount: 12,
    	leaveConfirm: '上传失败?'
      },
      pasteImage:true,
      toolbar: [
      'title',
      'bold',
      'italic',
      'underline',
      'strikethrough',
      'color',
      'ol',
      'ul',
      'blockquote',

      'table',
      'link',
      'image',
      'hr',
      'indent',
      'outdent',
      'alignment',
      'emoji'],
    	emoji: {
    	    imagePath: '{#WWW}public/images/emoji/'
    	}
      //optional options
    });
})
</script>
